/**
* Copyright (C) 2012-2017 ZEEI Inc.All Rights Reserved.
* 项目名称：gems
* 文件名称：StationPointController.java
* 包  名  称：com.zeei.mcs.controller
* 文件描述：站房和测点信息
* 创建日期：2017年7月11日下午1:51:58
*
* 修改历史
* 1.0 sunqian 2017年7月11日下午1:51:58 创建文件
* 2.0 yuyunjian 2018年11月19日下午1:51:58
*/
package com.zeei.ems.base.controller;

import java.util.*;
import java.util.stream.Collectors;


import com.github.pagehelper.PageInfo;

import com.zeei.ems.base.page.PageParamVO;

import com.zeei.ems.base.result.ResultVO;
import com.zeei.ems.base.service.StationPointService;

import com.zeei.ems.base.util.StringUtil;

import com.zeei.ems.base.vo.QueryStationPointParam;
import com.zeei.ems.base.vo.StationPointVO;

import com.zeei.ems.meet.model.TaskNewVO;
import com.zeei.ems.meet.service.TaskNewService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * @类型名称：StationPointController
 * @类型描述：测点信息管理
 * @功能描述：测点信息管理
 * @创建作者：sunqian
 */
@Api(value = "测点信息管理controller", tags = { "测点信息管理接口" })
@Controller
@RequestMapping("/ems/station")
public class StationPointController extends BasicController {

	public static final Log LOG = LogFactory.getLog(StationPointController.class);
	
	@Autowired
	StationPointService stationPointService;
	@Autowired
    TaskNewService taskNewService;

	@ApiOperation(value = "站点列表", notes = "站点列表", httpMethod = "POST")
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public ResultVO<StationPointVO> queryStationPoint(
			@ApiParam(name = "排口数据的参数类", value = "排口数据的参数类") QueryStationPointParam param,
			@ApiParam(name = "分页参数实体类", value = "分页参数实体类") PageParamVO pageParam,
			@ApiParam(name = "标准编码", value = "标准编码") Integer scode,
			@ApiParam(name = "多個測點編碼", value = "多個測點編碼") String points) {
		if (StringUtil.isNotEmpty(points)) {
			List<String> pointCodes = StringUtil.splitToList(points);
			param.setPointCodes(pointCodes);
		}
		PageInfo<StationPointVO> pageInfo = stationPointService.queryStationPoint(param, pageParam, scode);
		return this.createResultVO(pageInfo.getList(), null, true, null, (int) pageInfo.getTotal());
	}

	@ApiOperation(value = "站点列表", notes = "站点列表", httpMethod = "POST")
	@RequestMapping(value = "/dropdown", method = RequestMethod.POST)
	@ResponseBody
	public List<StationPointVO> queryComboStationPoint(String systemType) {
		return stationPointService.queryStationPointBySystemType(systemType);
	}

	@ApiOperation(value = "一张图站点列表", notes = "一张图站点列表", httpMethod = "POST")
	@RequestMapping(value = "/list/map", method = RequestMethod.POST)
	@ResponseBody
	public List<StationPointVO> queryMapStationPoint(String systemType) {
		List<StationPointVO> stationPointVOS = stationPointService.queryStationPointBySystemType(systemType);
		if (!CollectionUtils.isEmpty(stationPointVOS)){
			List<TaskNewVO> taskNewList = taskNewService.listTaskNewCurrent();
			stationPointVOS.forEach(point -> {
				List<TaskNewVO> taskList = taskNewList.stream().filter(task->task.getIsOverdue() == 1 &&
				task.getPointCode().equals(point.getPointCode())).collect(Collectors.toList());
				if (!CollectionUtils.isEmpty(taskList)){
					point.setIsOverdue(1);
				}else{
					point.setIsOverdue(0);
				}
			});
		}

		return stationPointVOS;
	}
}